package myky.com.doctorapp.model

import com.xiangyao.train.utils.RxScedulerHelper
import io.reactivex.Observable
import myky.com.doctorapp.api.ApiManager
import myky.com.doctorapp.base.BaseEntity

import myky.com.doctorapp.contract.SuccessfulActivityContract
import myky.com.doctorapp.entity.DoctorEntity
import myky.com.doctorapp.utils.Constants
import myky.com.doctorapp.utils.RequestBodyBuilder

/**
 * Description:
 *
 * @author wuyangwuyang
 * Created by 2019/3/7 on 10:22
 */
class SuccessfulActivityModel : SuccessfulActivityContract.Model {

    /**
     * 医生病历授权更新
     */
    override fun empowerUpdate(doctorId: Int): Observable<BaseEntity<String>> {
        val requestBodyBuilder = RequestBodyBuilder.Builder()
        requestBodyBuilder.params("version", Constants.CURRENTVERSION)
        requestBodyBuilder.params("doctorid", doctorId.toString())
        requestBodyBuilder.params("casepermission", "1")

        val requestBody = requestBodyBuilder.build()
        return ApiManager.getApistore().empowerUpdate(requestBody).compose(RxScedulerHelper.io_main())
    }

    /**
     * 获取医生信息
     */
    override fun getDoctorDeatails(doctorId: String, version: String): Observable<BaseEntity<DoctorEntity.PayLoadEntity>> {
        val requestBodyBuilder = RequestBodyBuilder.Builder()

        requestBodyBuilder.params("id", doctorId).params("version", version)

        val map = requestBodyBuilder.map

        return ApiManager.getApistore().getDoctorDetails(map)
    }


    override fun empower(doctorId: Int): Observable<BaseEntity<String>> {
        val requestBodyBuilder = RequestBodyBuilder.Builder()
        requestBodyBuilder.params("version", Constants.CURRENTVERSION)
        requestBodyBuilder.params("doctorid", doctorId.toString())

        val requestBody = requestBodyBuilder.build()
        return ApiManager.getApistore().empower(requestBody).compose(RxScedulerHelper.io_main())
    }
}
